﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Reflection;
using System.ComponentModel;

namespace WPF.Controls.QuerySelector
{
    public static partial class Selectors
    {
       public static object find(this FrameworkElement element, string expr)
       {
           object obj = null;
           if (expr.Contains(":"))
           {
               Panel panel = element as Panel;
               string filter = expr.Substring(1);
               switch (filter)
               {
                   case "first":
                       obj = panel.Children[0];
                       break;
                   case "last":
                       obj = panel.Children[panel.Children.Count - 1];
                       break;
                   case "even":
                       obj = panel.Children.Cast<UIElement>().Where((child, index) => index % 2 == 0);
                       break;
                   case "odd":
                       obj = panel.Children.Cast<UIElement>().Where((child, index) => index % 2 == 1);
                       break;
                   
               }
               if(filter.Contains("eq"))
               {
                   int index =Convert.ToInt32(filter.Substring(3).Replace(")", ""));
               }
               //lt less than
               //header 
           }
           return obj;
       }

       private static object expr(FrameworkElement element,string expr)
       {
           object elementIndex = 0;
           Panel panel = element as Panel;
           switch (expr)
           {
               case "first":
                   elementIndex=0;
                   break;
               case "last":
                   elementIndex = panel.Children.Count - 1;
                   break;
               case "even":
                    var query =
        panel.Children.Cast<UIElement>().Where((child, index) => index % 2 == 0);

                  
                   break;

           }

           return elementIndex;
       }

        //hidden,visible 

        //Form Filters
        //enabled disabled checked selected 
    }
}
